using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.ServiceModules;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.MiddlewareModules.Modules
{
    /// <summary>
    /// 认证授权中间件模块
    /// </summary>
    public class AuthenticationMiddlewareModule : IMiddlewareModule
    {
        public string ModuleName => "认证授权中间件";
        public int Priority => 4;
        public bool EnableInDevelopment => true;
        public bool EnableInProduction => true;
        public bool EnableInFastMode => true;
        public ModulePermission RequiredPermission => ModulePermission.AuthenticationServices;
        public bool IsCriticalModule => true; // 关键中间件

        public void ConfigureMiddleware(WebApplication app, IConfiguration configuration)
        {
            // 启用认证
            app.UseAuthentication();
            
            // 启用授权
            app.UseAuthorization();
        }

        public void ConfigureMinimalMiddleware(WebApplication app, IConfiguration configuration)
        {
            // 精简认证功能 - 只配置认证
            app.UseAuthentication();
        }

        public bool ValidateConfiguration(IConfiguration configuration)
        {
            // 认证授权中间件无特殊配置要求
            return true;
        }
    }
}
